package com.execl.client.hystrix;

import com.execl.client.UserClientService;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

// 熔断处理
@Component
@Slf4j
public class UserServiceHystrix implements FallbackFactory<UserClientService>{

    @Override
    public UserClientService create(Throwable throwable) {
        log.error("异常原因:{}", throwable.getMessage(), throwable);
        return new UserClientService() {
            @Override
            public String findByName(String username) {
                //出现异常，自定义返回内容，保证接口安全
                log.error("feign调用报错: "+throwable.getMessage());
                return throwable.getMessage();
            }
        };
    }
}
